<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>杨澎锴的实践作业26-vue.js组件</title>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  </head>

  <body>
    <h1>vuejs组件</h1>
    <section>
      <div id="app">
        <my-post
          v-for="post in posts"
          :key="post.id"
          :title="post.title"
          :published="post.published"
        ></my-post>
      </div>
      <script>
        Vue.component("my-post", {
          // props属性来接受来自外部数据
          props: ["title", "published"],
          template: "<div><h3>{{title}}</h3><p>{{published}}</p></div>",
        });
        var app7 = new Vue({
          el: "#app",
          data: {
            posts: [
              { id: 1, title: "china", published: "2020Beijing" },
              { id: 2, title: "USA", published: "LOSANGLES" },
              { id: 3, title: "UK", published: "2020London" },
            ],
          },
        });
      </script>
    </section>
  </body>
</html>
